set auto_path [concat [pwd]/../../pkg/tkMD $auto_path ]

package require tkMD 1.1
namespace import Data::*
if { [llength $argv] == 1 } {
  set protocol [lindex $argv 0]
  if ![file exists $protocol.tcl] { error "Do not have $protocol.tcl under current folder!"}
} else {
   puts "Usage example: whamrun.tcl protocol1"
   exit
}
set nreplica 1
source $protocol.tcl

# combine eql.dat and eql.en together.
batch_combine [pwd]/$protocol eql.dat eql.en eql.sum
# cat eql.sum with different com but same other parameters(type,peptide for example).
if { $nreplica == 1 } {
set result [batch_cat [pwd]/$protocol eql.sum $protocol/@pept/type_@type/com_@com/eql.sum --combine com --save [pwd]/data/$protocol]
} else {
set result [batch_cat [pwd]/$protocol eql.sum $protocol/@pept/type_@type/com_@com/run@i/eql.sum --combine i com --save [pwd]/data/$protocol]
}
set sumfiles {}
foreach dict $result {
    lappend sumfiles [dict get $dict fname]
}
#set sumfiles [Path::searchfiles [pwd]/data/$protocol *.eql.sum ]
#for each summary file , calculate the histogram and window average based on COM from 0 to 40 A with 41 bins. 
foreach f $sumfiles {
    set title [read_title $f]
    win_ave_file $f COM 0 40 41 $title $f.com
}

exit

